﻿using System.Linq;
using System.Windows;

namespace WPFTemplateLib.WpfHelpers
{
    /// <summary>
    /// WPF 窗口帮助类
    /// </summary>
    public static class WpfWindowHelper
    {
        /// <summary>
        /// [dlgcy] 获取激活的窗口
        /// </summary>
        /// <returns>激活的窗口，没有则为null</returns>
        public static Window GetActiveWindow()
        {
            int windowsCount = Application.Current.Windows.Count;
            Window[] windows = new Window[windowsCount];
            Application.Current.Windows.CopyTo(windows, 0);
            Window activeWindow = windows.FirstOrDefault(x => x.IsActive);
            return activeWindow;
        }
    }
}